﻿<UserControl x:Class="Deployment.Data.UI.Controls.Connection.ConnectionEditableList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:c="clr-namespace:Deployment.Data.UI.Controls.Connection"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <ListView x:Name="list" 
                  Grid.Column="0" Grid.Row="0"
                  ItemsSource="{Binding Path=Connections}"
                  ClipToBounds="True" 
                  ScrollViewer.CanContentScroll="True"
                  ScrollViewer.HorizontalScrollBarVisibility="Auto"
                  MinHeight="100"
                  MouseDoubleClick="lsv_connections_MouseDoubleClick"
                  VerticalAlignment="Stretch" SelectionChanged="list_SelectionChanged">
            <ListView.Resources>
                <Style TargetType="{x:Type GridViewColumnHeader}">
                    <Setter Property="HorizontalContentAlignment" Value="Left"/>
                </Style>
            </ListView.Resources>

            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Name"
                            Width="200"
                            DisplayMemberBinding="{Binding Name}"/>
                </GridView>
            </ListView.View>
        </ListView>

        <StackPanel Grid.Column="1" Grid.Row="0" Orientation="Vertical" Margin="4,4,4,0" VerticalAlignment="Top">
            <Button Content="Add connection" Padding="4,0,4,0" Click="AddConnection_Click"/>
            <Button Content="Remove selected" Margin="0,4,0,0" Click="RemoveConnection_Click">
                <Button.Style>
                    <Style>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=list, Path=SelectedIndex}"
                                                             Value="-1">
                                <Setter Property="Button.IsEnabled" Value="False"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
        </StackPanel>
    </Grid>
</UserControl>
